;Lab 3: Motors and PWM
;ECE 372 Fall 09 
;Lab Group 6
;Dan Ford, Kokou Gniningan, Manny Martinez
;November 17, 2009

;ASM interrupt service routine

			#include	p18f4550.inc
			EXTERN		ASMcount
			EXTERN		count1_dc
			EXTERN		count1_max
			EXTERN		direction

			code
PWM_motor

PWMOUT 		EQU 	PORTC

			;if ASMcount == 0, set output
test1		MOVLW 	0x0
			SUBWF 	ASMcount,0
			BNZ 	test2
			MOVF	direction,0
			MOVWF	PWMOUT,0
		
			;if ASMcount == duty cycle, clear output
test2		MOVF 	count1_dc,0
			SUBWF 	ASMcount,0
			BNZ 	pass
			MOVLW	0x0
			MOVWF	PWMOUT,0
pass
			INCF	ASMcount,1
			;increment ASMcount
			;if ASMcount == full period, clear it
			;if not, return 
test3		MOVF 	count1_max,0
			SUBWF 	ASMcount,0
			BNZ 	escape
			CLRF	ASMcount
escape		
			RETURN

			GLOBAL	PWM_motor
			END

